#include "Rock.h"
#include "Box.h"
#include "RSManager.h"
#include "Sprite.h"
#include "Box.h"
#include "GameDefine.h"
#include "ShareComponents.h"
#include "Camera.h"

Rock::Rock(Box* box) : Object(box, ObjAnti_DYNAMID), MoveObject()
{
	init();
}


Rock::~Rock(void)
{
}

void Rock::init()
{
	this->_sprite = RSManager::getInstance()->getSprite(ROCK);
	time_animation = 0;
	_box->_size = _sprite->getRenderSize();
	this->AssignMove(_box);
	_box->_v.x= 0;
	_box->_v.y= -0.9f;
	on_ground = false;
	_isAlive = true;
	_hits = 15;
}

void Rock::update()
{
	if(_hits < 0)
	{
		_isAlive  = false;
	}
	if(_box->getTop() < gl_camera->getTop())
	{
		_isAlive = false;
	}
	if(isOnSpace())
	{
		//xai nua gia toc khi roi
		_box->_v.y -= g / 1.20f;
	}
	if(isOnGround())
	{
		on_ground = !on_ground;
		if(on_ground)
			_box->_v.y = 1.50f;
		else
			fallDown();		
	}
	move();
	time_animation += GAME_TIME;
	if(time_animation > 100)
	{
		time_animation = 0;
		_sprite->Next();
	}
}

void Rock::render()
{
	_sprite->Render(_box->_position);
}

Box* Rock::getCollisionBox()
{
	float delta =  50;
	_colBox->_size = _box->_size;
	_colBox->_position = _box->_position;
	_colBox->_v = _box->_v;
	_colBox->_size.x -= delta;
	_colBox->_size.y -= delta;
	_colBox->_position.y += delta /2.0f;
	_colBox->_position.x += delta /2.0f;
	return _colBox;
}
